package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
import org.jboss.seam.async.Schedule ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IUserDao;
import com.hy.erp.inventory.pojo.User;
import com.hy.erp.inventory.pojo.interfaces.IUser;
import com.hy.erp.inventory.service.interfaces.IUserService;


/**
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-8；时间：下午02:36:57</li>
 * <li>字段类型：long；字段名称：serialVersionUID</li>
 * <li>设计目的：用户维护服务</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@Name("userService")
@ Scope ( ScopeType.SESSION )
@ Stateless
public class UserService
						extends
						AbstractBusinessService < IUser >
																implements
																IUserService
{

	private static final long	serialVersionUID	=
														122778171996664974L ;
	/**
	 * 构造函数
	 */
	public UserService(){
		super ( );
	}

	@ Override
	public boolean addUser (
								User user )
	{
		if(user==null)
		{
			return true;
		}
		else
		{
			IUserDao dao=( IUserDao ) this.getDao ( IUser.class );
			IUser iUser= user;
			return dao.persist ( iUser ) ;
		}
	}

	@ Override
	public Integer removeUser (
								String [ ] userIds )
	{
		if ( ( null == userIds )
			     || ( userIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				IUserDao dao=( IUserDao ) this.getDao ( IUser.class );
				return dao.remove ( userIds );
			}
	}

	@SuppressWarnings("unused")
	@ Override
	public boolean modifyUser (
								User user )
	{
		if ( ( null == user ) || ( null == user.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			IUserDao dao=( IUserDao ) this.getDao ( IUser.class );
			IUser u=user;
			
			if ( null == u )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (dao.merge ( u )!=null) ;
		}
		
	}

	@ Override
	public List < IUser > allUserList ( )
	{
		IUserDao dao=( IUserDao ) this.getDao ( IUser.class );
		return dao.find ( );
	}

	@ Override
	public String [ ] addUser (
								Object [ ] iUsers )
	{
		IUserDao dao=( IUserDao ) this.getDao ( IUser.class );
		User[] users=new User[iUsers.length];
		
		for(int i=0;i<iUsers.length;i++)
		{
			User user=( User ) iUsers[i];
			users[i]=user;
		}
		return dao.persist ( users ) ;
	}

}
